package com.ybkj.daijia.server.model;

import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.springframework.util.CollectionUtils;

/**
 * 提成表
 *
 * @author Shine
 */

public class DriverLevel extends Base {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private String name;//名称

    private TimePoint timePoint;//提成时间点

    private Long companyId;

    private String companyName;

    private Integer type;//0简单  1复杂

    private List<DriverLevelDetail> driverLevelDetails;//简单提成

    private List<DriverLevelMoneyTimeDetail> driverLevelMoneyTimeDetails;//复杂提成

    private boolean driverChecked;// 1司机是否选中当前提成 (代驾提成)

    private boolean driverCarChecked;// 1司机是否选中当前提成 (专车提成)

    private boolean driverPaotuiChecked;// 1司机是否选中当前提成 (跑腿提成)

    private boolean driverFreightChecked;// 1司机是否选中当前提成 (货运提成)

    private boolean driverZhuanxianChecked;// 1路线是否选中当前提成 (城际专线提成)

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Long getCompanyId() {
        return companyId;
    }

    public void setCompanyId(Long companyId) {
        this.companyId = companyId;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public List<DriverLevelDetail> getDriverLevelDetails() {
        return driverLevelDetails;
    }

    public void setDriverLevelDetails(List<DriverLevelDetail> driverLevelDetails) {
        this.driverLevelDetails = driverLevelDetails;
    }

    public List<DriverLevelMoneyTimeDetail> getDriverLevelMoneyTimeDetails() {
        return driverLevelMoneyTimeDetails;
    }

    public void setDriverLevelMoneyTimeDetails(
        List<DriverLevelMoneyTimeDetail> driverLevelMoneyTimeDetails) {
        this.driverLevelMoneyTimeDetails = driverLevelMoneyTimeDetails;
    }


    public boolean isDriverChecked() {
        return driverChecked;
    }

    public void setDriverChecked(boolean driverChecked) {
        this.driverChecked = driverChecked;
    }

    public boolean isDriverCarChecked() {
        return driverCarChecked;
    }

    public void setDriverCarChecked(boolean driverCarChecked) {
        this.driverCarChecked = driverCarChecked;
    }


    public boolean isDriverPaotuiChecked() {
        return driverPaotuiChecked;
    }

    public void setDriverPaotuiChecked(boolean driverPaotuiChecked) {
        this.driverPaotuiChecked = driverPaotuiChecked;
    }


    public boolean isDriverFreightChecked() {
        return driverFreightChecked;
    }

    public void setDriverFreightChecked(boolean driverFreightChecked) {
        this.driverFreightChecked = driverFreightChecked;
    }

    public boolean isDriverZhuanxianChecked() {
        return driverZhuanxianChecked;
    }

    public void setDriverZhuanxianChecked(boolean driverZhuanxianChecked) {
        this.driverZhuanxianChecked = driverZhuanxianChecked;
    }

    public Integer getType() {
        if (null == type) {
            return 0;
        }
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public TimePoint getTimePoint() {
        if (null == timePoint) {
            return TimePoint.startDrive;
        }
        return timePoint;
    }


    public void setTimePoint(TimePoint timePoint) {
        this.timePoint = timePoint;
    }

    public DriverLevelDetail getDeatil(Date travelDate) {
        if (null == travelDate) {
            return null;
        }
        if (CollectionUtils.isEmpty(driverLevelDetails)) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(travelDate);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int hourminute = (hour * 60) + minute;
        for (DriverLevelDetail dld : driverLevelDetails) {
            if (!dld.isEmpty()) {
                if (dld.getStartHour() <= dld.getEndHour()) {
                    if (hourminute >= (dld.getStartHour() * 60) + dld.getStartMinute()
                        && hourminute <= (dld.getEndHour() * 60) + dld.getEndMinute()) {
                        return dld;
                    }
                } else {
                    int start1 = (dld.getStartHour() * 60) + dld.getStartMinute();
                    int end1 = 24 * 60;

                    int start2 = 0;
                    int end2 = (dld.getEndHour() * 60) + dld.getEndMinute();

                    if ((hourminute >= start1 && hourminute <= end1) || (hourminute >= start2
                        && hourminute <= end2)) {
                        return dld;
                    }

                }

            }
        }
        return null;
    }

    public DriverLevelMoneyTimeDetail getMoneyTimeDeatil(Date travelDate) {
        if (null == travelDate) {
            return null;
        }
        if (CollectionUtils.isEmpty(driverLevelMoneyTimeDetails)) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(travelDate);
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        int minute = calendar.get(Calendar.MINUTE);
        int hourminute = (hour * 60) + minute;
        for (DriverLevelMoneyTimeDetail dlmtd : driverLevelMoneyTimeDetails) {
            if (!dlmtd.isEmpty()) {
                if (dlmtd.getStartHour() <= dlmtd.getEndHour()) {
                    if (hourminute >= (dlmtd.getStartHour() * 60) + dlmtd.getStartMinute()
                        && hourminute <= (dlmtd.getEndHour() * 60) + dlmtd.getEndMinute()) {
                        return dlmtd;
                    }
                } else {
                    int start1 = (dlmtd.getStartHour() * 60) + dlmtd.getStartMinute();
                    int end1 = 24 * 60;

                    int start2 = 0;
                    int end2 = (dlmtd.getEndHour() * 60) + dlmtd.getEndMinute();

                    if ((hourminute >= start1 && hourminute <= end1) || (hourminute >= start2
                        && hourminute <= end2)) {
                        return dlmtd;
                    }

                }

            }
        }
        return null;
    }

    public enum TimePoint {
        /**
         * 预约时间
         */
        serviceTime,
        /**
         * 出发时间
         */
        startDrive,
        /**
         * 结算时间
         */
        finishTime
    }

}
